From 63afd80f48171e255e05e7ebcde732b555b597e5 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Mon, 24 Aug 2009 08:03:46 +0100 Subject: [PATCH] vtpm: Fix hashed-memory file writing. There is a bug in the vtpm_manager that has to do with hashing and saving the NVM memory files (vtpm_dm_%d.data). The file is not truncated when it is written and this results in the hash becoming invalid because of the extra bits at the end of the file. This patch adds O_TRUNC to the flags when opening the file. More details on this issue are in the bug report on bugzilla=20 http://bugzilla.xensource.com/bugzilla/show_bug.cgi?id=3D1488 Signed-off-by: Matt Fioravante --- tools/vtpm_manager/manager/securestorage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/vtpm_manager/manager/securestorage.c b/tools/vtpm_manager/manager/securestorage.c index e4bb5dbb9b..d5e6ffda15 100644 --- a/tools/vtpm_manager/manager/securestorage.c +++ b/tools/vtpm_manager/manager/securestorage.c @@ -199,7 +199,7 @@ TPM_RESULT VTPM_Handle_Save_NVM(VTPM_DMI_RESOURCE *myDMI, // TODO: How to properly return from these. Do we care if we return failure // after writing the file? We can't get the old one back. // TODO: Backup old file and try and recover that way. - fh = open(myDMI->NVMLocation, O_WRONLY | O_CREAT, S_IREAD | S_IWRITE); + fh = open(myDMI->NVMLocation, O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE); if ( (bytes_written = write(fh, sealed_NVM.bytes, buffer_len(&sealed_NVM) ) != (long) buffer_len(&sealed_NVM))) { vtpmlogerror(VTPM_LOG_VTPM, "We just overwrote a DMI_NVM and failed to finish. %ld/%ld bytes.\n", bytes_written, (long)buffer_len(&sealed_NVM)); status = TPM_IOERROR; -- 2.30.2